#ifndef __DISPLAY_TEXT_H__
#define __DISPLAY_TEXT_H__

// Includes
#include <PA9.h>       // Include for PA_Lib


#include "Init.h"


//find the the value of the digit and return
//the image location on the sprite strip
int calcTextImage(u16 num, int loc)
{
	//since val is an int, it will cut off an decimal values
	int val = num/loc; 
	//keep subtracting ten, until val is less than ten
	while(val >= 10)
	{
		val -= 10;
	}
	
	//return the appropriate image location
	if(val == 9)
		return 10;
	else if(val == 8)
		return 9;
	else if(val == 7)
		return 8;
	else if(val == 6)
		return 7;
	else if(val == 5)
		return 6;
	else if(val == 4)
		return 5;
	else if(val == 3)
		return 4;
	else if(val == 2)
		return 3;
	else if(val == 1)
		return 2;
	else if(val == 0)
		return 1;
	else 
		return 0;
}

//not set up for negative numbers
//only works for positive numbers
void displayText(int scr, int spr, u16 num, int loc)
{
	int img = 0;
	

	switch(loc)
	{
	case 1:
		//one's place
		img = calcTextImage(num, loc);
		break;
	case 10:
		//ten's place
		if(num < 10)
			img = 0; //blank
		else
			img = calcTextImage(num, loc);
		break;
	case 100:
		//hundred's place
		if(num < 100)
			img = 0; //blank
		else
			img = calcTextImage(num, loc);
		break;
	case 1000:
		//thousand's place
		if(num < 1000)
			img = 0; //blank
		else
			img = calcTextImage(num, loc);
		break;
	case 10000:
		//ten thousand's place
		if(num < 10000)
			img = 0; //blank
		else
			img = calcTextImage(num, loc);
		break;
	default:
		//output blank by default
		img = 0; //blank
		break;
	}
	
	
	PA_SetSpriteAnim(scr, spr, img);
}


	


#endif  //__DISPLAY_TEXT_H__
